<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">挪用</h4>
</div>
<form id="transfer-ap-form" action="/xqc/inventory/transfer-ap-ajax" method="post"  onsubmit="return checkTransferAPForm();">
    <div class="modal-body">
        <div class="row">
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">可挪用数量</label>
                <label style="padding-top: 8px;text-align: left;" class="col-sm-8 control-label">{{ $transferAP->instant }}</label>
            </div>
            <div class="form-group" style="padding-bottom: 30px;">
                <label style="padding-top: 8px;text-align: right;" class="col-sm-3 control-label">挪用数量</label>
                <div class="col-sm-8">
                    <input type="text" style="margin-top: 5px;" class="transfer_num_" name="param[transfer_num]" data-max="{{ $transferAP->instant }}" value="{{ 0 }}" placeholder="挪用数量" required>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        {{ csrf_field() }}
        <input type="hidden" name="param[id]" value="{{ $id }}">
        <input type="hidden" name="action" value="transfer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="submit" class="btn btn-primary">确定</button>
    </div>
</form>
<script language="JavaScript" type="text/javascript">
    function checkTransferAPForm(){
        var transferNumObj = $('input[name="param[transfer_num]"]');
        var max = transferNumObj.data('max');
        var transferNum = transferNumObj.val();
        if(Number(transferNum) < 0 ||Number(transferNum) > max){
            swal('数量有误', '', 'error');
            return false;
        }
        return true;
    }
    $(function () {
        $(".transfer_num_").inputmask("integer",
            {
                onKeyValidation: function () {
                    if($(this).val() > $(this).data('max') || $(this).val() < 0){
                        $(this).val(0);
                    }
                }
            }
        );
        $("#transfer-ap-form").ajaxForm(function (data) {
            if (typeof data === 'object') {
                if (data.status) {
                    $("#tModal").modal('hide');
                    $(".modal-backdrop").remove();
                    $('body').removeClass('modal-open');
                    toastr.success('提交成功 !');
                    $.pjax.reload('#pjax-container');
                } else {
                    swal(data.message, '', 'error');
                }
            }
        });
    });
</script>
